package com.hyt.it.ogt.kq.main.controller.bm;

import com.hyt.common.apiInfor.ApiResponse;
import com.hyt.it.ogt.kq.common.bm.utils.Constant;
import com.hyt.it.ogt.kq.main.controller.base.BaseController;
import com.hyt.it.ogt.kq.service.bm.service.ISendMessageService;
import com.hyt.it.ogt.kq.service.gov.model.param.fjCityBm.SendMessageParam;
import com.hyt.loginfo.service.IPtSecretKeyService;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;


/**
 * @author 朱振宇
 * @since 2024-01-24
 */
@Api(tags = "600.福建行政执法资格考试报名")
@RestController
@RequestMapping("/fjCityBm")
@Slf4j
public class FjCityBmController extends BaseController {

    @Resource
    private ISendMessageService iSendMessageService;
    
    @Resource
    private IPtSecretKeyService iPtSecretKeyService;


    @ApiOperation(value = "601.1.1 发送短信", notes = "20000:成功")
    @ApiOperationSort(value = 1)
    @RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
    public ApiResponse<Object> sendMessage(@RequestBody SendMessageParam sendMessageParam) {
        String secretKey = sendMessageParam.getSecretKey();
        log.info("# sendMessage secretKey:{}", secretKey);
        String configSecretKey = iPtSecretKeyService.getSecretKey("fjzf", "bm", "sendmsg");
        log.info("# sendMessage configSecretKey:{}, secretKey", configSecretKey, secretKey);
        if(StrUtil.isBlankIfStr(configSecretKey) || StrUtil.isBlankIfStr(secretKey) ) {
            return ApiResponse.<Object>builder().code(31451106).data(null).build();
        }
        if(!secretKey.equals(configSecretKey)) {
            return ApiResponse.<Object>builder().code(31451106).data(null).build();
        }
        iSendMessageService.sendMessageToMQ(getOfficeId(), getDeptId(), getUserId(), sendMessageParam);
        return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).build();
    }

    @ApiOperation(value = "601.1.2 获取短信模板", notes = "20000:成功")
    @ApiOperationSort(value = 2)
    @RequestMapping(value = "/findSendMessageTemplateList", method = RequestMethod.GET)
    public ApiResponse<Object> findSendMessageTemplateList() {
        return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(iSendMessageService.findSendMessageTemplateList(getOfficeId())).build();
    }

    @ApiOperation(value = "601.1.3 获取需要发送的总短信数", notes = "20000:成功")
    @ApiOperationSort(value = 3)
    @RequestMapping(value = "/getTotalMessageNum", method = RequestMethod.GET)
    public ApiResponse<Object> getTotalMessageNum(String projectId, Integer sendType, Integer messageNum) {
        if (Objects.isNull(messageNum)) {
            return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(0).build();
        }
        return ApiResponse.builder().code(Constant.RESPONSE_CODE_SUCCESS).data(iSendMessageService.getSendMessageNum(projectId, getDeptId(), sendType, messageNum)).build();
    }
}
